#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;

int n;
vector<pair<int, int>> a;
vector<pair<int, int>> g[N];
vector<int> ans, tmp;

bool check(int k)
{
    tmp.clear();
    int cnt = 0;
    for (int i = 1;i <= n;i++) {
        if (g[i].size() == 0) continue;
        int tt = min((int)g[i].size(), k - cnt), res = 0;
        for (int j = tt - 1;j >= 0;j--) {
            int need = max(0, k - cnt - (j + 1));
            if (need <= g[i][j].first) { res = j + 1;break; }
        }
        for (int j = 0;j < res;j++) tmp.push_back(g[i][j].second);
        cnt += res;
    }
    return cnt == k;
}

void solve()
{
    cin >> n;
    a.clear();
    for (int i = 1;i <= n;i++) g[i].clear();
    for (int i = 1;i <= n;i++) { int x, y; cin >> x >> y; a.push_back({ x,y }); g[x].push_back({ y,i }); }
    for (int i = 1;i <= n;i++) sort(g[i].begin(), g[i].end(), greater<pair<int, int>>());

    int l = 0, r = n;
    while (l < r) {
        int mid = (l + r + 1) >> 1;
        if (check(mid)) {
            l = mid;
            ans = tmp;
        } else r = mid - 1;
    }
    cout << l << '\n';
    for (int it : ans) cout << it << ' ';
    cout << '\n';
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
    // #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    cin >> T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}